#ifndef SHADER_H
#define SHADER_H

#include <QOpenGLShaderProgram>
#include <QDebug>

class Shader : public QOpenGLShaderProgram
{
public:
    Shader(const char* vertexPath, const char* fragmentPath)
    {
        if (!addShaderFromSourceFile(QOpenGLShader::Vertex, vertexPath)) {
            qDebug() << "Vertex shader compile failed:" << log();
            return;
        }

        if (!addShaderFromSourceFile(QOpenGLShader::Fragment, fragmentPath)) {
            qDebug() << "Fragment shader compile failed:" << log();
            return;
        }

        // 链接着色器程序
        if (!link())
        {
            qDebug() << "Shader program link failed:" << log();
            return;
        }
    }

    void use()
    {
        bind();
    }
};


#endif // SHADER_H
